﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Student_Score_System
{
    public class Score

    {
        private Dictionary<E_CourseType, float> dicScore;

        public Score()
        {
            dicScore = new Dictionary<E_CourseType, float>();
        }
        /*

        #region 第一种做法



        /// <summary>

        /// 英语

        /// </summary>

        private float _English;

        public float English

        {

            get { return _English; }

            set { _English = VerifyValidRange(value); }

        }

        /// <summary>

        /// 中文

        /// </summary>

        private float _Chinese;

        public float Chinese

        {

            get { return _Chinese; }

            set { _Chinese = VerifyValidRange(value); }

        }

        /// <summary>

        /// 地理

        /// </summary>

        private float _Geography;

        public float Geography

        {

            get { return _Geography; }

            set { _Geography = VerifyValidRange(value); }

        }

        /// <summary>

        /// 历史

        /// </summary>

        private float _History;

        public float History

        {

            get { return _History; }

            set { _History = VerifyValidRange(value); }

        }

        /// <summary>

        /// 生物

        /// </summary>

        private float _Biology;

        public float Biology

        {

            get { return _Biology; }

            set { _Biology = VerifyValidRange(value); }

        }



        /// <summary>

        /// 化学

        /// </summary>

        private float _Chemistry;

        public float Chemistry

        {

            get { return _Chemistry; }

            set { _Chemistry = VerifyValidRange(value); }

        }



        #endregion

        */

        #region 第二种做法

        /// <summary>

        /// 英语

        /// </summary>

        public float English

        {
            get { return GetScore(E_CourseType.English); }
            set { SetScore(E_CourseType.English, value); }
        }

        private void SetScore(object english, float value)
        {
            throw new NotImplementedException();
        }

        private float GetScore(object english)
        {
            throw new NotImplementedException();
        }

        /// <summary>

        /// 中文

        /// </summary>

        public float Chinese

        {
            get { return GetScore(E_CourseType.Chinese); }
            set { SetScore(E_CourseType.Chinese, value); }
        }
        /// <summary>

        /// 地理

        /// </summary>

        public float Geography

        {
            get { return GetScore(E_CourseType.Geography); }
            set { SetScore(E_CourseType.Geography, value); }
        }
        /// <summary>

        /// 历史

        /// </summary>

        public float History

        {
            get { return GetScore(E_CourseType.History); }
            set { SetScore(E_CourseType.History, value); }
        }
        /// <summary>

        /// 生物

        /// </summary>

        public float Biology

        {
            get { return GetScore(E_CourseType.Biology); }
            set { SetScore(E_CourseType.Biology, value); }
        }

        /// <summary>

        /// 化学

        /// </summary>

        public float Chemistry

        {
            get { return GetScore(E_CourseType.Chemistry); }
            set { SetScore(E_CourseType.Chemistry, value); }
        }

        #endregion

        /// <summary>

        /// 根据类型设置成绩

        /// </summary>

        /// <param name="type"></param>

        /// <param name="value"></param>

        public void SetScore(E_CourseType type, float value)

        {
            value = VerifyValidRange(value);
            dicScore[type] = value;
        }

        /// <summary>

        /// 根据类型获取成绩

        /// </summary>

        /// <param name="type"></param>

        /// <returns></returns>

        public float GetScore(E_CourseType type)

        {
            return dicScore[type];
        }

        /// <summary>

        /// 验证分数有效性

        /// </summary>

        /// <param name="value"></param>

        /// <returns></returns>

        private float VerifyValidRange(float value)

        {
            if (value < 0)
                return 0;
            if (value > 150)
                return 150;
            return value;
        }
    }
}
